package com.lizhi.yun.core.role.handler;/**
 * @program: spring-boot
 * @name UppRoleService
 * @description:
 * @author: lizhi
 * @create: 2020-04-11 18:24
 */

import com.lizhi.common.yun.entity.ListResponseResult;
import com.lizhi.common.yun.enums.RoleStateEnum;
import com.lizhi.yun.db.dao.UppRoleDao;
import com.lizhi.yun.db.pojo.UppRolePOJO;
import com.lizhi.mybatis.interceptor.PageBounds;
import com.lizhi.utils.date.DateUtils;
import com.lizhi.yun.base.BaseHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 *@program: spring-boot
 *@name UppRoleService
 *@description:
 *@author: lizhi
 *@create: 2020-04-11 18:24
 */
@Slf4j
@Service
public class UppRoleHandler extends BaseHandler {

    @Resource
    private UppRoleDao uppRoleDao;

    public ListResponseResult doMain(Map<String, Object> map) {
        PageBounds pageBounds = getPageBounds(map);
        List<UppRolePOJO> listUppRoleDO = uppRoleDao.selectByMap(map, pageBounds);
        return getListResult(pageBounds.getCountRows(), listUppRoleDO, map);
    }

    /**
     *功能描述  添加一条完整记录
     * @author lizhi
     * @date 2020/4/14
     * @param record:
     * @return int
     */
    public ListResponseResult insertRecord(UppRolePOJO record) {
        record.setIstTm(DateUtils.getNowDate());
        record.setState(RoleStateEnum.NORMAL.getEnValue());
        return getListResult(uppRoleDao.insertRecord(record));
    }

    /**
     *功能描述  按Id(主键)修改指定列的值
     * @author lizhi
     * @date 2020/4/14
     * @param record:
     * @return int
     */
    public ListResponseResult updateByIdSelective(UppRolePOJO record) {
        record.setUpdTm(DateUtils.getNowDate());
        /*设置状态为正常*/
        record.setState(RoleStateEnum.NORMAL.getEnValue());
        return getListResult(uppRoleDao.updateByIdSelective(record));
    }

    /**
     * 删除角色
     * @param roleId
     * @return
     */
    public ListResponseResult doDelete(String roleId){
        return getListResult(uppRoleDao.deleteById(roleId));
    }

    /**
     *功能描述  通过Id(主键)查询一条记录
     * @author lizhi
     * @date 2020/4/14
     * @param roleId:
     * @return com.lizhi.db.upp.pojo.UppRolePOJO
     */
    public ListResponseResult selectById(String roleId) {
        return getListResult(uppRoleDao.selectById(roleId));
    }

    /**
     *功能描述
     * @author lizhi
     * @date 2020/4/13
     * @param state:
     * @return java.util.List<com.lizhi.db.upp.pojo.UppRolePOJO>
     */
    public ListResponseResult selectList(String state) {
        List<UppRolePOJO> listUppRolePOJO = uppRoleDao.selectList(state);
        return getListResult(listUppRolePOJO);
    }

    public ListResponseResult isNotexists(String roleId) {
        UppRolePOJO uppRolePOJO = uppRoleDao.selectById(roleId);
        if (null == uppRolePOJO) {
            return getListResult(true);
        }
        return getListResult(false);
    }
}
